import vtkActor from "@kitware/vtk.js/Rendering/Core/Actor";
import vtkMapper from "@kitware/vtk.js/Rendering/Core/Mapper";
import vtkPolyData from "@kitware/vtk.js/Common/DataModel/PolyData";
import vtkPoints from "@kitware/vtk.js/Common/Core/Points";
import vtkCellArray from "@kitware/vtk.js/Common/Core/CellArray";
import vtkDataArray from "@kitware/vtk.js/Common/Core/DataArray";
import { BActor } from "./BActor";
import { ACTOR_TYPE } from "../interface";
import vtkConeSource from "@kitware/vtk.js/Filters/Sources/ConeSource";
import { Vector3 as V3 } from "stl-typescript";
import { Vector3 } from "@kitware/vtk.js/types";
import vtkAppendPolyData from "@kitware/vtk.js/Filters/General/AppendPolyData";
import { die } from "mobx/dist/errors";
export class TCell extends BActor {
  instance: vtkActor = vtkActor.newInstance();
  readonly type = ACTOR_TYPE.GRAPHIC_ACTOR;
  createdBy = "default";
  dofNext: Vector3[] = [];
  constructor(direction: Vector3, color: Vector3, centers: Vector3[]) {
    super();
    const coneHeight = 2; // 控制圆锥体的高度
    const coneRadius = 0.5; // 控制圆锥体的底面半径
    let coneSource: vtkConeSource = vtkConeSource.newInstance();
    // 创建一个用于合并多个几何体的 AppendPolyData
    const appendPolyData = vtkAppendPolyData.newInstance();
    this.dofNext = [];
    centers.forEach((center) => {
      const a: Vector3 = [
        center[0] - (direction[0] * coneHeight) / 2,
        center[1] - (direction[1] * coneHeight) / 2,
        center[2] - (direction[2] * coneHeight) / 2,
      ];
      this.dofNext.push([
        center[0] - direction[0] * coneHeight,
        center[1] - direction[1] * coneHeight,
        center[2] - direction[2] * coneHeight,
      ]);
      // const a = center. - (direction * coneHeight) / 2;
      coneSource = vtkConeSource.newInstance({
        height: coneHeight,
        radius: coneRadius,
        resolution: 30, // 分辨率，越高越圆滑
        direction, // 设置圆锥体的方向
        center: a, // 设置圆锥体的中心
      });
      appendPolyData.addInputData(coneSource.getOutputData());
    });

    const mapper = vtkMapper.newInstance();
    mapper.setInputConnection(appendPolyData.getOutputPort());

    this.instance.setMapper(mapper);
    this.instance.getProperty().setColor(...color); // 设置圆锥体颜色
  }
}
